package com.itheima.guozi2;

public class Cooker implements Runnable {
    private Desk desk;

    public Cooker(Desk desk) {
        this.desk=desk;
    }

    @Override
    public void run() {
        //摊煎饼
        //死循环
        while (true){
            //判断做够了吗
            synchronized (desk.getObj()) {
                if(desk.getCount()>0){
                    //判断桌子上有没有
                    if(desk.isFlag()){
                        //有  等着
                        try {
                            desk.getObj().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else {
                        //没有  做一个煎饼 叫人吃
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println(Thread.currentThread().getName()+"摊了一个煎饼");
                      desk.setFlag(true);
                        desk.getObj().notifyAll();
                    }

                }else {
                    System.out.println("今天已经没面了 下班");
                    break;
                }
            }


        }

    }
}
